
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>修改密码</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
</head>
<body>

  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>修改账户</legend>
  </fieldset>

  <form class="layui-form" action="">
    <div class="layui-form-item">
      <label class="layui-form-label">原密码</label>
      <div class="layui-input-inline">
        <input type="hidden" name="id" value="${user.id}">
        <input type="password" id="pass" name="pass" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">新密码</label>
      <div class="layui-input-inline">
        <input type="password" id="newPwd" name="newPwd" lay-verify="pass" placeholder="请输入新密码" autocomplete="off" class="layui-input">
      </div>
      <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">确认新密码</label>
      <div class="layui-input-inline">
        <input type="password" id="reNewPass" name="reNewPass" lay-verify="reNewPass" placeholder="请输入新密码" autocomplete="off" class="layui-input">
      </div>
      <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
    </div>

    <div class="layui-form-item">
      <div class="layui-input-block">
        <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">修改</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      </div>
    </div>
  </form>

  <script src="/layuiadmin/layui/layui.js"></script>
  <script>
    layui.config({
      base: '/layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use('index');
  </script>
  <script>
    layui.use(['index','form'], function(){
      let $ = layui.jquery
              ,form = layui.form;

      //自定义验证规则
      form.verify({
        pass: [
          /^[\S]{6,12}$/
          ,'密码必须6到12位，且不能出现空格'
        ]
        ,reNewPass: function(value){
          if (value!=$("#newPwd").val()){
            return "两次新密码输入不一致";
          }
        }
      });

      //监听提交
      form.on('submit(demo1)', function(data){
        $.ajax({
          url:'updatePassword',
          type:'post',
          data:data.field,
          async:true, dataType: "json", traditional: true,
          success:function(json){
            window.top.layer.msg(json.msg);
            $("#pass").val('');
            $("#newPwd").val('');
            $("#reNewPass").val('');
          },error:function(){
            window.top.layer.msg('请求失败');
          }
        });
        return false;
      });
    });
  </script>

</body>

</html>
